package top.huhuiyu.springboot.study.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import top.huhuiyu.springboot.study.base.BaseDataResult;
import top.huhuiyu.springboot.study.base.BaseResult;
import top.huhuiyu.springboot.study.base.PageBean;
import top.huhuiyu.springboot.study.base.PageResult;
import top.huhuiyu.springboot.study.entity.Software;
import top.huhuiyu.springboot.study.service.SoftwareService;

import java.util.List;

/**
 * @author 胡辉煜
 */
@RestController
@RequestMapping("/software")
@RequiredArgsConstructor
public class SoftwareController {
  private final SoftwareService softwareService;

  @PostMapping("")
  public BaseResult insert(@RequestBody Software software) {
    return softwareService.insert(software);
  }

  @GetMapping("/{id}")
  public BaseDataResult<Software> queryByKey(@PathVariable("id") Integer id) {
    return softwareService.queryByKey(id);
  }

  @GetMapping("/{pn}/{ps}")
  public BaseDataResult<PageResult<List<Software>>> query(Software software, @PathVariable("pn") Integer pn, @PathVariable("ps") Integer ps) {
    return softwareService.query(software, PageBean.instance(pn, ps));
  }

  @GetMapping("/mapping/{pn}/{ps}")
  public BaseDataResult<PageResult<List<Software>>> queryMapping(Software software, @PathVariable("pn") Integer pn, @PathVariable("ps") Integer ps) {
    return softwareService.queryMapping(software, PageBean.instance(pn, ps));
  }

  @GetMapping("/result/{pn}/{ps}")
  public BaseDataResult<PageResult<List<Software>>> queryResult(Software software, @PathVariable("pn") Integer pn, @PathVariable("ps") Integer ps) {
    return softwareService.queryResult(software, PageBean.instance(pn, ps));
  }

  @DeleteMapping("/{id}")
  public BaseResult delete(@PathVariable("id") Integer id) {
    return softwareService.delete(id);
  }

  @PutMapping("")
  public BaseResult update(@RequestBody Software software) {
    return softwareService.update(software);
  }

}
